compare=function(xx,yy) {
  ### NOTE: This hard codes order of names, which is based on order written in felm() line. Do not change!
  if (sum(rownames(xx$coefficients)==rownames(yy$coefficients))==nrow(xx$coefficients)) {
    kk=data.table("variable"=rownames(xx$coefficients),"assmt"=xx$coefficients[,1],"mkt"=yy$coefficients[,1])
    kk$variable=c("Racial Share","Median Income","Owner Percent","Unemployment","GINI","SNAP",
                  "Square Feet","Bathrooms","Patio","Pool","Fireplace","Year Built")
    kk$colvec=ifelse(kk$variable %in% c("Racial Share","Median Income","Owner Percent","Unemployment","GINI","SNAP"),"red","black")
    kk$ratio=kk$mkt/kk$assmt
    kk$ratio.norm=kk$ratio-1
    kk$diff=abs(kk$mkt)-abs(kk$assmt)
    kk=kk[order(kk$ratio,decreasing=T),]
    kk
  }
}


getbarplot=function(xx,titleinput,racelabel,vers="diff",spread=.38,lims) {
  num=length(xx$variable)
  if (vers=="ratio") {
    xx=xx[order(xx$ratio.norm,decreasing=T),]
    if (missing(lims)) { lims=c(min(xx$ratio.norm),max(xx$ratio.norm)) }
    barplot(xx$ratio.norm,ylim=lims,space=.5,main=titleinput,ylab="",col=xx$colvec) 
  }
  if (vers=="diff") {
    xx=xx[order(xx$diff,decreasing=T),]
    if (missing(lims)) { lims=c(2*min(xx$diff),1.2*max(xx$diff)) }
    barplot(xx$diff,ylim=lims,space=.5,main=titleinput,ylab="",col=xx$colvec) 
  }
  endpoint=num*(1+spread)
  xx$variable[which(xx$variable=="Racial Share")]=racelabel
  text(x=seq(.65,endpoint,by=(endpoint-.65)/(num-1)),y=lims[1],pos=3,par("usr")[3]-.25,srt=60, adj=1,xpd=T,labels=xx$variable,cex=1.2)
}
